package service;

import java.math.BigInteger;
import java.util.List;

import beans.Agent;
import beans.Terminal;

import dao.QueryDAO;
import dao.TerminalDao;


public class TerminalService implements TerminalServiceInterface {

    private List<Terminal> terminals = null;

    QueryDAO queryDAO = new QueryDAO();
    TerminalDao terminalDao = new TerminalDao();

    String sql = null;
    String hql = null;

    public List<Terminal> getTerminalPage(Agent agent, int rows, int page) {
        return terminalDao.getTerminalPage(agent, rows, page);
    }

    public int getTerminalNumber(Agent agent) {
        sql = "select count(t.terminal_id) from branch b,terminal t where t.terminal_branch_id = b.branch_id and b.branch_agent_id = ?";
        return ((BigInteger)queryDAO.queryUniques(sql, agent.getId())).intValue();
    }
    
    public void deleteTerminal(String ids) {//delete 操作不能用表别名
        sql = "delete from terminal where terminal_id in ("+ids+")";
        queryDAO.queryExcute(sql);
    }

}